package fields;

import java.io.IOException;
import java.io.RandomAccessFile;

import data.AbstractDataType;
import fileProcessing.ParsingException;

public class FileCollectionData extends AbstractField{

	private String fieldValue;
	private long file_ptr;

	public FileCollectionData(String fieldName, String cat, String value) {
		super(fieldName,cat);
		fieldValue = value;
	}

	public void addData(RandomAccessFile dataFile, String line) throws ParsingException {}
	public void saveContent(RandomAccessFile dataFile) throws ParsingException{
		try {
			dataFile.seek(dataFile.length());
			file_ptr = dataFile.getFilePointer();
			dataFile.writeUTF(fieldValue);
		} catch (IOException e) {
			throw new ParsingException("Trouble writing collection data.");
		}
	}

	public AbstractDataType getValue(RandomAccessFile dataFile) throws ParsingException {
		return null;
	}
	
	public String getContent(RandomAccessFile dataFile) throws ParsingException{
		String result = "";
		try {
			dataFile.seek(file_ptr);
			result = dataFile.readUTF();
		} catch (IOException e) {
			throw new ParsingException("Error getting value for collection data:"+e.getMessage());
		}
		return result;
	}

	@Override
	public int verify(String s) {
		// TODO Auto-generated method stub
		return 0;
	}

}
